<script>
	import {
		ref
	} from 'vue'
	import pageAnimation from '@/js_sdk/event770-pageAnimation/animation.js'
	import {
		iceSetStorage,
		iceGetStorage,
		iceRemoveStorage
	} from '@/utils/common.js'
	import {
		inject
	} from 'vue';
	import {
		postHandExamPage
	} from './src/api';
	// const handleBlur = () => {
	// 	console.log('浏览器失焦');
	// }
	export default {
		onLaunch: function() {
			iceSetStorage('iceCheckCheat', false)
			console.log('App Launch')
			// iceRemoveStorage('id')
			// iceRemoveStorage('userId')
			pageAnimation({
				durationIn: 300,
				durationOut: 300,
				// mode: "top",
				mode: "skew",
				// mode: "3d",
				// mode: "3d2",
				auto: true,
				except: []
			});
			iceGetStorage('userId').then(res => {
				if(res){
					uni.navigateTo({
						url: `/pages/kaoshiPre/index`
					})
				}
				
			})
		},
		onShow: function() {
			console.log('App Show')
			iceGetStorage('test').then(res => {
				console.log(res)
			})
		},
		// async
		onHide: function() {
			console.log('App Hide')
			// 检测作弊 
			// const iceCheckCheat = await iceGetStorage('iceCheckCheat') 
			// 如果这里用 async 和 await 会导致 pinia undefined
			const pinia = inject('pinia');
			const postHandExamPages = () => {
				const sbm = pinia.state.value.questionList.submitData
				sbm.status = 2
				postHandExamPage(sbm).then(res => {
					console.log('检测出作弊');
					if (res.code == 0) {
						uni.navigateTo({
							url: '/pages/kaoshiPre/index?msg=' + res.msg
						})
					}
				})
			}
			iceGetStorage('iceCheckCheat').then(res => {
				if (!res) return
				pinia.state.value.questionList && postHandExamPages()
			})
		}
	}
</script>

<style lang="scss">
	/*每个页面公共css */
	@import 'uview-plus/theme.scss';
	@import "uview-plus/index.scss";
	@import 'uni.scss';
	// 跳也动画
	@import '@/js_sdk/event770-pageAnimation/css.css';
	// 登录页背景炫彩动画
	@import '@/static/css/xuancai.css';
</style>